"use strict"
/**
 * @param {import("egg").Application} app
 */
module.exports = app => {
	const Sequelize = app.Sequelize
	const sequelize = app.model
	let KeyWordResponse = sequelize.define("KeyWord", {
		key_name: {
			type: Sequelize.STRING,
			allowNull: false,
			comment: "关键字规则名称"
		},
		aid: {
			type: Sequelize.INTEGER,
			allowNull: false,
		},
		trigger_key: {
			type: Sequelize.STRING,
			allowNull: false,
			comment: "关键词",
		},
		trigger_type: {
			comment: "关键字触发类型 1回复触发 2.进入触发",
			type: Sequelize.TINYINT,
			allowNull: false,
		},
		stat: {
			type: Sequelize.TINYINT,
			comment: "是否生效"
		},
		update_at: {
			type: Sequelize.DATE,
			defaultValue: sequelize.literal("CURRENT_TIMESTAMP"),
			get() {
				return Date.parse(this.getDataValue("update_at"))
			}
		},
		response_type: {
			//"1","2","3" w文本, 图片,小程序
			type: Sequelize.TINYINT
		},
		respone_set: {
			type: Sequelize.STRING,
			comment: "{textContent,imgTitle,imgPath,imgDesc}",
			get() {
				let str = this.getDataValue("respone_set")
				if(str)
					return JSON.parse(str)
				else{
					return {}
				}
			},
			set(val) {
				this.setDataValue("respone_set", JSON.stringify(val))
			},
			defaultValue: "{}"
		}
	}, {
		tableName: "key_word_response",
		timestamps: false,
		deletedAt: false,
	})
	return KeyWordResponse
}
/**
 *  	let desc = {
        textContent: "文本",
        imgTitle: "图片标题",
        imgDesc: "图片描述",
        imgHref: "图片链接",
        promTitle: "小程序标题",
        promPath: "小程序路径",
        imgPath: "上传图片的路径"
      }; 
 */